<template>
    <van-skeleton v-show="gjp" title :row="10"/>
        <van-nav-bar title="分类" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" fixed />
        <div style="height: 45px;"></div>
        <van-search v-model="value" placeholder="请输入搜索关键词" @search="searchval" />
        <van-pull-refresh v-model="isLoading" success-text="刷新成功" @refresh="onRefresh">
            <van-row>

                <van-col span="6">
                    <van-sidebar v-model="active">
                        <van-sidebar-item v-for="item in categoriesApiData" :title="item.cat_name" />
                    </van-sidebar>
                </van-col>
                <van-col span="18">
                    <div v-for="item in categoriesApiData[active]?.children">
                        <h5>{{ item.cat_name }}</h5>
                        <router-link :to="{ name: 'goods', params: { query: item.cat_name } }">
                            <van-grid :column-num="4">
                                <van-grid-item v-for="items in item.children" :icon="items.cat_icon"
                                    :text="items.cat_name" />
                            </van-grid>
                        </router-link>
                    </div>
                </van-col>
            </van-row>
        </van-pull-refresh>
        <van-submit-bar button-text="去结算" @click="all">
        </van-submit-bar>

</template>

<script setup>
import { categoriesApi } from '@/api/api';
import { showToast } from 'vant';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
let router = useRouter()
let gjp=ref(false)
let categoriesApiData = ref([])
categoriesApi().then(res => {
    gjp.value=true
    categoriesApiData.value = res.data.message
})
let active = ref(0)
const loading = ref(false);
const onRefresh = () => {
    setTimeout(() => {
        showToast('刷新成功');
        loading.value = false;
        count.value++;
    }, 1000);
}
let searchval = () => {
    router.push('/search')
}
let all = () => {
    router.push('/order')
}
setInterval(()=>{
    gjp.value=false
},2000)
</script>

<style lang="scss" scoped></style>